package leetcode.code1576;

import leetcode.IDebug;

public class Solution implements IDebug {

	public String modifyString(String s) {
		char[] ss = s.toCharArray();
		int last = 0;
		if (ss[0] == '?') {
			last = 97;
			ss[0] = (char) last;
		} else {
			last = ss[0];
		}
		for (int i = 1; i < ss.length; i++) {
			char cur = ss[i];
			if (cur == '?') {
				last = this.next(last);
				ss[i] = (char) last;
			} else {
				if (cur == last) {
					ss[i - 1] = (char) this.next(last);
				}
				last = cur;
			}
		}
		return new String(ss);
	}

	private int next(int last) {
		last += 1;
		if (last > 122) {
			last = 97;
		}
		return last;
	}

	@Override
	public void debug1() {
		System.out.println("?zs");
		System.out.println(this.modifyString("?zs"));
	}

	@Override
	public void debug2() {
		System.out.println("ubv?w");
		System.out.println(this.modifyString("ubv?w"));
	}

	@Override
	public void debug3() {
		String test = "j?qg??b";
		System.out.println(test);
		System.out.println(this.modifyString(test));
	}

	@Override
	public void debug4() {
		String test = "??yw?ipkj?";
		System.out.println(test);
		System.out.println(this.modifyString(test));
	}
	public void debug5() {
		String test = "???????a?????b?????c?????";
		System.out.println(test);
		System.out.println(this.modifyString(test));
	}
	public void debug6() {
		String test = "?a?b?c?d?ez?a";
		System.out.println(test);
		System.out.println(this.modifyString(test));
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
		so.debug6();

		System.out.println((int) 'a');
		System.out.println((int) 'z');
	}

}
